b9acecd85ae15644ca0adaa5635df01419d3df35,portal-impl/src/com/liferay/portal/tools/sourceformatter/XMLSourceProcessor.java,XMLSourceProcessor,formatWebXML,#,689
Before Change
}
protected void formatWebXML() throws IOException {
if (portalSource) {
Properties properties = new Properties();
String propertiesContent = fileUtil.read(
BASEDIR + "portal-impl/src/portal.properties");
PropertiesUtil.load(properties, propertiesContent);
String[] locales = StringUtil.split(
properties.getProperty(PropsKeys.LOCALES));
Arrays.sort(locales);
Set<String> urlPatterns = new TreeSet<String>();
for (String locale : locales) {
int pos = locale.indexOf(StringPool.UNDERLINE);
String languageCode = locale.substring(0, pos);
urlPatterns.add(languageCode);
urlPatterns.add(locale);
}
StringBundler sb = new StringBundler();
for (String urlPattern : urlPatterns) {
sb.append("\t<servlet-mapping>\n");
sb.append("\t\t<servlet-name>I18n Servlet</servlet-name>\n");
sb.append(
"\t\t<url-pattern>/" + urlPattern +"/*</url-pattern>\n");
sb.append("\t</servlet-mapping>\n");
}
File file = new File(
BASEDIR + "portal-web/docroot/WEB-INF/web.xml");
String content = fileUtil.read(file);
String newContent = trimContent(content, false);
int x = newContent.indexOf("<servlet-mapping>");
x = newContent.indexOf(
"<servlet-name>I18n Servlet</servlet-name>", x);
x = newContent.lastIndexOf("<servlet-mapping>", x) - 1;
int y = newContent.lastIndexOf(
"<servlet-name>I18n Servlet</servlet-name>");
y = newContent.indexOf("</servlet-mapping>", y) + 19;
newContent =
newContent.substring(0, x) + sb.toString() +
newContent.substring(y);
x = newContent.indexOf("<security-constraint>");
x = newContent.indexOf(
"<web-resource-name>/c/portal/protected</web-resource-name>",
x);
x = newContent.indexOf("<url-pattern>", x) - 3;
y = newContent.indexOf("<http-method>", x);
y = newContent.lastIndexOf("</url-pattern>", y) + 15;
sb = new StringBundler();
sb.append("\t\t\t<url-pattern>/c/portal/protected</url-pattern>\n");
for (String urlPattern : urlPatterns) {
sb.append(
"\t\t\t<url-pattern>/" + urlPattern +
"/c/portal/protected</url-pattern>\n");
}
newContent =
newContent.substring(0, x) + sb.toString() +
newContent.substring(y);
if ((newContent != null) && !content.equals(newContent)) {
fileUtil.write(file, newContent);
System.out.println(file);
}
}
else {
String webXML = ContentUtil.get(
"com/liferay/portal/deploy/dependencies/web.xml");
String[] includes = new String[] {"**\\web.xml"};
List<String> fileNames = getFileNames(new String[0], includes);
for (String fileName : fileNames) {
String content = fileUtil.read(BASEDIR + fileName);
if (content.equals(webXML)) {
fileName = StringUtil.replace(
fileName, StringPool.BACK_SLASH, StringPool.SLASH);
processErrorMessage(fileName, fileName);
}
}
}
After Change
"com/liferay/portal/deploy/dependencies/web.xml");
if (content.equals(webXML)) {
processErrorMessage(fileName, fileName);
}
return content;